home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / DocShell / ShlEvtHd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  10.5 KB  |  381 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ShlEvtHd.cp
  3.  
  4.     Contains:    Shell event handlers (and others, for now)
  5.  
  6.     Owned by:    Eric House
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <18>      9/9/95    TJ        Included TempObj.h
  13.         <17>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  14.                                     without kOD prefix!
  15.         <16>      9/8/95    TÇ        1282092 FB2: Shell must check nil after SOM
  16.                                     new
  17.         <15>      9/5/95    TÇ        FBs: 1266428, 1274419, 1274421, 1274423,
  18.                                     1274429, 1274435 Fixed the Shell to handle
  19.                                     multiple documents in a process. Needed for
  20.                                     CyberDog.
  21.         <14>     8/25/95    eeh        1263528: cleanup
  22.         <13>     8/22/95    eeh        1230007: refbal-inspired cleanup
  23.         <12>     8/15/95    TÇ        1262179 FB: Shell calls BlockMove() in many
  24.                                     places
  25.         <11>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  26.                                     refcount is wrong in
  27.                                     ODRefCntObjectsomUninit.
  28.         <10>     5/26/95    RR        #1251403: Multithreading naming support
  29.          <9>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  30.          <8>     4/27/95    eeh        1240648: pass kODNULL to SaveACopyAs
  31.          <7>     3/21/95    JP        1192027: Include ODRgstry & change some
  32.                                     constant names
  33.          <6>     2/21/95    eeh        1214783: cleanup
  34.          <5>     2/20/95    TÇ        #1210979 BB: 5-$ Bugs need to be evaluated
  35.                                     and removed from Shell
  36.          <4>     9/29/94    RA        1189812: Mods for 68K build.
  37.          <3>     9/26/94    TÇ        #1188679 Save A Copy As Stationery
  38.          <2>     7/28/94    TÇ        put ifdef ODDEBUG around DebugStr.
  39.                                     #1155844
  40.          <1>     6/30/94    TÇ        first checked in
  41.          <0>     6/29/94    SV        SOMverted
  42.          <4>     3/31/94    eeh        bug# 1151750: more scripting support for
  43.                                     operations on draft
  44.          <3>     3/25/94    eeh        bug# 1151750: more scripting support for
  45.                                                                         operations on draft.
  46.          <2>     3/24/94    eeh        bug# 1151750: scripting support for
  47.                                     operations on draft
  48.          <4>      2/8/94    TÇ        Throw -> THROW & some code clean up
  49.          <3>      2/7/94    TÇ        more fixes to compile with PPC Headers
  50.          <2>     1/11/94    eeh        nuked FrameEventHandler class; mods to
  51.                                     others
  52.          <1>    11/19/93    eeh        first checked in
  53.  
  54.  
  55.     To Do:
  56.     In Progress:
  57.         
  58. */
  59.  
  60.  
  61. #ifndef _PLFMDEF_
  62. #include "PlfmDef.h"
  63. #endif
  64.  
  65.  
  66. #ifndef _ODUTILS_
  67. #include <ODUtils.h>
  68. #endif
  69.  
  70. #ifndef _SHLEVTHD_
  71. #include "ShlEvtHd.h"
  72. #endif
  73.  
  74. #ifndef _SHPRPACC_
  75. #include "ShPrpAcc.h"
  76. #endif
  77.  
  78. #ifndef _SEUTILS_
  79. #include "SEUtils.h"
  80. #endif
  81.  
  82. #ifndef _DOCUTILS_
  83. #include "DocUtils.h"
  84. #endif
  85.  
  86. #ifndef _ODREGISTRY_
  87. #include "ODRgstry.xh"
  88. #endif
  89.  
  90. #ifndef _RLSHELL_
  91. #include <RlShell.h>
  92. #endif
  93.  
  94. #ifndef SOM_ODWindow_xh
  95. #include <Window.xh>
  96. #endif
  97.  
  98. #ifndef _PASCLSTR_
  99. #include "PasclStr.h"
  100. #endif
  101.  
  102. #ifndef _EXCEPT_
  103. #include "Except.h"
  104. #endif
  105.  
  106. #ifndef _PLFMFILE_
  107. #include <PlfmFile.h>
  108. #endif
  109.  
  110. #ifndef SOM_ODDocument_xh
  111. #include <Document.xh>
  112. #endif
  113.  
  114. #ifndef _ODDEBUG_
  115. #include "ODDebug.h"
  116. #endif
  117.  
  118. #ifndef _TEMPOBJ_
  119. #include "TempObj.h"
  120. #endif
  121.  
  122. #pragma segment ShPrpAcc
  123.  
  124. //==============================================================================
  125. // Constants
  126. //==============================================================================
  127.  
  128. //==============================================================================
  129. // Scalar Types
  130. //==============================================================================
  131.  
  132. //==============================================================================
  133. // Local Classes
  134. //==============================================================================
  135.  
  136. //==============================================================================
  137. // Global Variables
  138. //==============================================================================
  139.  
  140. //==============================================================================
  141. // Function Prototype
  142. //==============================================================================
  143.  
  144. //==============================================================================
  145. // HandlerObject
  146. //==============================================================================
  147.  
  148. //------------------------------------------------------------------------------
  149. // HandlerObject::HandlerObject
  150. //------------------------------------------------------------------------------
  151.  
  152. HandlerObject::HandlerObject(DescType theClass, ODObject* theObject,
  153.         ODSLong refCon)
  154. {
  155.     fObjectClass = theClass;
  156.     fTheObject = theObject;
  157.     fRefcon = refCon;
  158. }
  159.  
  160. //------------------------------------------------------------------------------
  161. // HandlerObject::GetClass
  162. //------------------------------------------------------------------------------
  163.  
  164. DescType HandlerObject::GetClass()
  165. {
  166.     return fObjectClass;
  167. }
  168.  
  169. //------------------------------------------------------------------------------
  170. // HandlerObject::GetObject
  171. //------------------------------------------------------------------------------
  172.  
  173. ODObject* HandlerObject::GetObject()
  174. {
  175.     return fTheObject;
  176. }
  177.  
  178. //==============================================================================
  179. // ShellEventHandler
  180. //==============================================================================
  181.  
  182. //------------------------------------------------------------------------------
  183. // ShellEventHandler::ShellEventHandler
  184. //------------------------------------------------------------------------------
  185.  
  186. ShellEventHandler::ShellEventHandler(DescType theClass, ODObject* theObject,
  187.         ODSLong refCon) : HandlerObject(theClass, theObject, refCon)
  188. {
  189. }
  190.  
  191. //------------------------------------------------------------------------------
  192. // ShellEventHandler::Save
  193. //------------------------------------------------------------------------------
  194.  
  195. void ShellEventHandler::Save(AEDesc* whereFileSpec)
  196. {
  197.     RealShell* self = (RealShell*)fRefcon;
  198.     Environment* ev = self->GetEV();
  199.     ODSession* session = self->GetSession();
  200.     ODVolatile(session);
  201.  
  202.     // Note: this event acts upon the ACTIVE document in the process if
  203.     //     it is a plain Save event.
  204.     // If it is a "Save A Copy" event and specifies a destination, then
  205.     //    it will act upon the ACTIVE draft.
  206.     
  207.     // Most of the time there will be only one document & one draft, 
  208.     //    so this is fine, but FYI. -TÇ
  209.     
  210.     if (whereFileSpec->dataHandle == NULL)
  211.     {
  212.         ODSaveDocument(ev, session, ODGetActiveDocument(ev, session));
  213.     }
  214.     else
  215.     {
  216.         ODFileSpec fss;
  217.         ODBlockMove(*(whereFileSpec->dataHandle), &fss, sizeof(fss));
  218.         TempPlatformFile file = new PlatformFile;
  219.         file->Specify(&fss);
  220.         ODSaveACopyOfDraft(ev, session, ODGetActiveDraft(ev, session), file);
  221.     }
  222. }
  223.  
  224. //------------------------------------------------------------------------------
  225. // ShellEventHandler::Close
  226. // Closing the shell means closing the active window
  227. //------------------------------------------------------------------------------
  228.  
  229. void ShellEventHandler::Close(AEDesc* whereFileSpec, DescType saveOptions)
  230. {
  231.     RealShell* self = (RealShell*)fRefcon;
  232.     Environment* ev = self->GetEV();
  233.     ODSession* session = self->GetSession();
  234.  
  235.     ODUnused(whereFileSpec);
  236.     
  237.     WindowPtr platformWindow = kODNULL;
  238.     {
  239.     TempODWindow window = ODAcquireActiveWindow(ev, session);
  240.     if (window)
  241.         platformWindow = window->GetPlatformWindow(ev);
  242.     }
  243.     self->CloseWindow(platformWindow, saveOptions);
  244. }
  245.  
  246. //------------------------------------------------------------------------------
  247. // ShellEventHandler::CountElements
  248. //------------------------------------------------------------------------------
  249.  
  250. #ifdef TO_BE_DELETED
  251. static ODSLong CountDraftsInDocument( ODDocument* doc )
  252. {
  253. Environment*     ev             = somGetGlobalEnvironment();
  254.     ODSLong        result         = 0;        // current draft doesn't count
  255.     ODDraft*     thisDraft     = doc->AcquireBaseDraft(ev, kODDPReadOnly); // -- TÇ: $$$$$ Don't know if this is a true leak
  256.     ODDraft*     nextDraft     = kODNULL;
  257.     ODVolatile(result);
  258.     TRY
  259.         while ( true )
  260.         {
  261.             nextDraft = doc->AcquireDraft(ev,  kODDPReadOnly, kODNULL, thisDraft,    /* -- TÇ: $$$$$ Don't know if this is a true leak */
  262.                     kODPosLastAbove, kODTrue );
  263.             thisDraft = nextDraft;
  264.             ++result;
  265.         }
  266.     CATCH_ALL
  267.         ;
  268.     ENDTRY
  269.  
  270.     return result;
  271. }
  272. #endif /* TO_BE_DELETED */
  273.  
  274. #ifdef TO_BE_DELETED
  275. void ShellEventHandler::CountElements(DescType elemClass, AEDesc* result)
  276. {
  277.     ODSLong resultCount;
  278.     OSErr err = noErr;
  279.  
  280.     switch(this->GetClass())
  281.     {
  282.         case typeNull :
  283.             switch( elemClass )
  284.             {
  285.                 case cDraft :
  286.                     resultCount = CountDraftsInDocument(
  287.                             ((RealShell*)this->GetObject())->GetDocument() );
  288.                     break;
  289.                 case cWindow :
  290.                     resultCount = 1;
  291.                     break;
  292.                 default :
  293.                     err = errAEEventNotHandled;
  294.             }
  295.             break;
  296.  
  297.         case cWindow :
  298.             switch(elemClass)
  299.             {
  300.                 case cPart :
  301.                     resultCount = 1;        // only one root part (now)
  302.                     break;
  303.                 default :
  304.                     err = errAEEventNotHandled;
  305.             }
  306.             break;
  307.  
  308.         default :
  309.             err = errAEEventNotHandled;
  310.     }
  311.  
  312.     if (err != noErr)
  313.         THROW(err);
  314.     else
  315.         THROW_IF_ERROR(AECreateDesc(typeLongInteger, (Ptr)&resultCount,
  316.                 sizeof(resultCount), result));
  317. }
  318. #endif /* TO_BE_DELETED */
  319.  
  320. //------------------------------------------------------------------------------
  321. // ShellEventHandler::Clone
  322. //------------------------------------------------------------------------------
  323.  
  324. #ifdef TO_BE_DELETED
  325. void ShellEventHandler::Clone( AEDesc* whereto, AEDesc* result )
  326. {
  327.     ODUnused( whereto );
  328.     result->descriptorType = 'null';
  329.     result->dataHandle = NULL;
  330. }
  331. #endif /* TO_BE_DELETED */
  332.  
  333. //------------------------------------------------------------------------------
  334. // ShellEventHandler::Delete
  335. //------------------------------------------------------------------------------
  336.  
  337. #ifdef TO_BE_DELETED
  338. void ShellEventHandler::Delete()
  339. {
  340. Environment* ev = somGetGlobalEnvironment();
  341.     switch(this->GetClass() )
  342.     {
  343.         case cDraft :
  344.         {
  345.             ODDraft* selectedDraft = (ODDraft*)this->GetObject();
  346.             ODDocument* document = selectedDraft->GetDocument(ev);
  347.  
  348.             WASSERT( selectedDraft->GetRefCount(ev) <= 1 );
  349.  
  350.             ODDraft* fromDraft = document->AcquireDraft(ev,  kODDPReadOnly, kODNULL, /* -- TÇ: $$$$$ Don't know if this is a true leak */
  351.                     selectedDraft, kODPosFirstAbove, kODFalse );
  352.             WASSERT( selectedDraft->GetRefCount(ev) <= 1 );
  353.             WASSERT( fromDraft->GetRefCount(ev) <= 1 );
  354.             document->SaveToAPrevDraft(ev,  fromDraft, selectedDraft );
  355.             document->CollapseDrafts(ev,  fromDraft, selectedDraft );
  356.             ODReleaseObject(ev, selectedDraft );
  357.         }
  358.             break;
  359.         default :
  360.             THROW( errAEEventNotHandled );
  361.     }
  362. }
  363. #endif /* TO_BE_DELETED */
  364.  
  365. //==============================================================================
  366. // PartEventHandler
  367. //==============================================================================
  368.  
  369. //------------------------------------------------------------------------------
  370. // PartEventHandler::PartEventHandler
  371. //------------------------------------------------------------------------------
  372.  
  373. #ifdef TO_BE_DELETED
  374. PartEventHandler::PartEventHandler(DescType theClass, ODFrame* frame,
  375.         ODSLong refCon) : HandlerObject(theClass, (ODObject*)frame,
  376.         refCon)
  377. {
  378. }
  379. #endif /* TO_BE_DELETED */
  380.  
  381.